package org.de.maeyer.unit;

/**
 * @author Peter De Maeyer
 */
public abstract class MultiplyingUnit extends AbstractUnit {

	protected final double multiplier;

	protected final Unit multipliedUnit;

	public MultiplyingUnit(double multiplier, Unit multipliedUnit) {
		this.multipliedUnit = multipliedUnit;
		this.multiplier = multiplier;
	}

	@Override
	public double convertFrom(double value, Unit unit) {
		return multipliedUnit.convertFrom(value, unit) / multiplier;
	}

	@Override
	double convertTo(double value, MultiplyingUnit unit) {
		return unit.convertFrom(value * multiplier, multipliedUnit);
	}

	@Override
	double convertTo(double value, NonMultiplyingUnit unit) {
		return unit.convertFrom(value * multiplier, multipliedUnit);
	}
}
